package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.animations.Animation;
	import com.terrynoya.fight.animations.IAnimation;
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;

	public class AnimElemTime
	{
		public function AnimElemTime()
		{
			
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var chara:Character = data as Character;
			if(chara == null)
			{
				return 0;
			}
			var animation:IAnimation = chara.animationManager.currentAni;
			if(animation == null)
			{
				return 0;
			}
			var value:int = int(node.getChildAt(0).token.text);
			var eleId:int = value - 1;
			var aniTime:int = chara.animationManager.time;
			var eleStartTime:int = animation.getElementStartTime(eleId);
			var rlt:int = aniTime - eleStartTime;
			return rlt;
		}
		
		public static function parse(state:ParseState):Node
		{
			return state.buildParenNumberNode(true);
		}
	}
}